const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
//逻辑混淆
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = function(env, argv) {
	const isDebug = !!argv.env && argv.env.development == 0;
	let config = {
		entry: {
			"myeval": './src/index.js',
			"number-util": './lib/number-util.js'
		},
		output: {
			filename: "[name].min.js", // 生成的js 文件
			path: path.resolve(__dirname, 'dist'), // 打包生成的文件夹
			clean: true,
		},
		module: {
			rules: [{
				test: /\.js$/,
				loader: "babel-loader",
				exclude: /node_modules/,
			}]
		},
		plugins: []
	};
	if (isDebug) {
		config.devtool = "eval-cheap-module-source-map";
		config.devServer = {
			contentBase: path.join(__dirname, 'dist'),
			port: 8080,
			inline: true, //实时刷新
			open: false
		}
		config.plugins.push(new HtmlWebpackPlugin({
			template: './index.html',
			inject: "head",
			chunks: Object.getOwnPropertyNames(config.entry),
			scriptLoading: 'blocking'
		}));
	} else {
		config.plugins.push(new UglifyJsPlugin());
		config.target = ['es5'];
	}
	return config;
}
